#include "cc_malloc.h"
#include "cc_limits.h"
#include "cc_common.h"
#include "cc_stdlib.h"

#pragma warning(disable:4668)
#pragma warning(disable:4820)
#pragma warning(disable:4255)
#pragma warning(disable:4706)
#include <windows.h>

void * __cdecl cc_malloc(
	size_t size
	)
{
	HANDLE handle;
	if(!(handle = GetProcessHeap()))
		return NULL;

	return HeapAlloc(handle, 0, size);
}

void __cdecl cc_free(
	void *memBlock
	)
{
	if(memBlock == NULL)
		return;

	HeapFree(GetProcessHeap(), 0, memBlock);
}

void * __cdecl cc_calloc(
	size_t cnt,
	size_t size
	)
{
	void *ret = cc_malloc(size * cnt);
	if(!ret)
		return NULL;

	memset(ret, 0, size);
	return ret;
}

void * __cdecl cc_realloc(
	void *memBlock,
	size_t newSize
	)
{
	return HeapReAlloc(GetProcessHeap(), 0, memBlock, newSize);
}

#ifdef __cplusplus
void operator delete(
	void *p
)
{
	cc_free(p);
}
#endif